package com.tjsinfo.tjsoa.vote.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.common.PaginationSupport;
import com.tjsinfo.tjsoa.vote.vo.TVoteHead;

public class VoteHeadListAction extends Action {
	private IQbcDao qbcDao;
	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			DetachedCriteria criteria = DetachedCriteria.forClass(TVoteHead.class);
			criteria.add(Restrictions.eq("status", Integer.valueOf(2)));
			
			List<Order> orderList=new ArrayList<Order>();
			orderList.add(Order.desc("id"));
			
			Integer pageSize=12;
			String pageStr=request.getParameter("pageNo");
			if(pageStr==null)pageStr="0";
			int page=Integer.valueOf(pageStr).intValue();
			int startIndex=pageSize*page;
			PaginationSupport paginationSupport=qbcDao.findPageByCriteria(criteria,orderList, Integer.valueOf(pageSize),startIndex);
			request.setAttribute("paginationSupport", paginationSupport);			
			
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}
